package com.ithuameng.admin.app.system.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ithuameng.admin.app.system.model.UserRole;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * User role mapper
 *
 * @author ithuameng
 */
public interface UserRoleMapper extends BaseMapper<UserRole> {

    /**
     * 根据用户ID获取角色选择框列表
     *
     * @param userId 用户ID
     * @return 选中角色ID列表
     */
    @Select({
            "<script>",
            "SELECT r.id FROM t_role r",
            "LEFT JOIN t_user_role ur ON ur.role_id = r.id",
            "LEFT JOIN t_user u ON (u.id = ur.user_id and u.deleted='N')",
            "WHERE r.deleted='N' and ur.user_id=#{userId}",
            "</script>"
    })
    List<Long> listRoleByUserId(Long userId);
}
